const path = require('path')
const { DefinePlugin } = require('webpack')

const config = {
  mode: 'production',
  entry: './src/index.ts',
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [{ loader: 'ts-loader' }]
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.js', '.tsx', 'json']
  },
  plugins: [
    new DefinePlugin({
      API_VERSION: JSON.stringify(require('./package.json').version)
    })
  ],
}

module.exports = [
  {
    ...config,
    output: {
      path: path.resolve(__dirname, 'lib'),
      clean: true,
      filename: 'graph.back.js',
      libraryTarget: 'umd',
      libraryExport: 'default',
      library: 'GraphBack'
    },
    optimization: {
      minimize: false
    }
  },
  {
    ...config,
    output: {
      path: path.resolve(__dirname, 'lib'),
      filename: 'graph.back.min.js',
      libraryTarget: 'umd',
      libraryExport: 'default',
      library: 'GraphBack'
    },
    optimization: {
      minimize: true
    }
  }
]